package ca.abubakrsagar.breadboardsim;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * Handles the control of the components in the components panel.
 * @author Abubakr
 * @since June 13, 2012
 *
 */
public class ComponentsController implements MouseListener {

	private ComponentsPanel compPanel; // The components Panel.

	/**
	 * Creates a new components controller while associating the given compPanel to the local compPanel.
	 * @param compPanel The given components Panel.
	 */
	public ComponentsController(ComponentsPanel compPanel) {
		this.compPanel = compPanel;
		
	}

	/** 
	 * If the mouse is double clicked on a component, add that component into the toolbox.
	 */
	@Override
	public void mouseClicked(MouseEvent e) {
		if (e.getClickCount() >= 2 && !e.isConsumed()) {
			if (e.getSource() == compPanel.getLedComponent()) {
				compPanel.addLED();
			} else if (e.getSource() == compPanel.getResistorComponent()) {
				compPanel.addResistor();
			} else if (e.getSource() == compPanel.getSwitchComponent()){
				compPanel.addSwitch();
			}
			e.consume();
		}
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

}
